package com.tb.as_client;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;

import com.google.zxing.client.android.Utils.ZXingUtils;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//        Intent intent = new Intent(this, CaptureActivity.class);
//        this.startActivity(intent);
        ZXingUtils.startCaptureForResult(this,1);


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            //获取扫码结果
            String scanResult = data.getStringExtra("result_string");
            //去掉结尾的换行"\n"
            scanResult = scanResult.substring(0,scanResult.length() - 1);
            Log.d(getLocalClassName(), scanResult);
            //转至结果页面
            ((TextView)findViewById(R.id.text)).setText(scanResult);
        }
    }

}
